package come.tool.Fighting;

import java.awt.Graphics;
import java.util.ArrayList;
import java.util.List;

import org.come.until.Article;

import com.tool.tcp.GetTcpPath;
import com.tool.tcp.NewPart;
import com.tool.tcp.Sprite;
import com.tool.tcp.SpriteFactory;
/**
 * 战斗中人物数据
 * @author Administrator
 */
public class FightingManData {

	public static Boolean IS_XY_FS;//心猿是否分身了
    static String[] fbs;
	static List<String> drawDown;//绘制在脚底下
	static List<String> lingxistate;// 灵犀重复状态只绘制一次

	static List<String> fms;//
	static boolean lingxidraw;
	static{//法宝类型
		fbs=new String[]{"fbYsjl","fbJjl","fbDsc","fbQbllt","fbHlz","fbYmgs",
				"fbDsy","fbJqb","fbQw","fbBld","fbJge","fbFty","fbJljs","fbBgz","fbHd",
				"bbss","6018","6019","6022","6024","6025","6027","6028","7002","7008",
				"7015","7026","7033","7034","7035","9389","沧波","扶摇","甘霖","1231","1232","1866","1869","1873","1254","1260","1263",
				"以静制动","清心静气","失魂落魄","利刃加身","兽魂俯首",
				"凝神一击","刚柔兼备","幻影迷踪","虎踞龙蟠","气吞山河","明镜止水","气聚神凝","无坚不摧",
				"血蛊佑身","鱼龙潜跃","法魂护体","扑朔迷离","神不守舍","神龙摆尾","行气如虹","积羽沉舟","荆棘束身","23004","知耻后勇"};
		drawDown=new ArrayList<>();//绘制在脚底的素材编号
		drawDown.add("金");drawDown.add("木");
		drawDown.add("土");drawDown.add("水");
		drawDown.add("火");
		drawDown.add("1869");
		drawDown.add("1876");
		drawDown.add("1887");
		drawDown.add("1890");
		drawDown.add("一矢中的");
		drawDown.add("fbJge");

		lingxistate=new ArrayList<>();
		lingxistate.add("11006");
		lingxistate.add("11007");
		lingxistate.add("11010");
		lingxistate.add("11012");
		lingxistate.add("11013");
		lingxistate.add("11014");
		lingxistate.add("11015");
		lingxistate.add("11017");
		lingxistate.add("11018");
		lingxistate.add("11019");
		lingxistate.add("11025");
		lingxistate.add("11027");
		lingxistate.add("11029");
		lingxistate.add("11031");
		lingxistate.add("11032");

		lingxistate.add("11033");
		lingxistate.add("11034");
		lingxistate.add("11035");

		fms = new ArrayList<>();
		fms.add("12501");
		fms.add("12502");
		fms.add("12503");
		fms.add("12504");
		fms.add("12505");
		fms.add("12506");
		fms.add("12507");
		fms.add("12508");
		fms.add("12509");
		fms.add("12510");
		fms.add("12511");
		fms.add("12512");
		fms.add("12513");
		fms.add("12514");
		fms.add("12515");
		fms.add("12516");
		fms.add("12517");
		fms.add("12518");
		fms.add("12001");
		fms.add("12002");
		fms.add("12003");
		fms.add("12004");
		fms.add("12005");
		fms.add("12006");
		fms.add("12007");
		fms.add("12008");
		fms.add("12009");
		fms.add("12010");
		fms.add("12011");
		fms.add("12012");
		fms.add("12013");
		fms.add("12014");
		fms.add("12015");
		fms.add("12016");
		fms.add("12017");
		fms.add("12018");

		fms.add("12521");
		fms.add("12522");
		fms.add("12523");
		fms.add("12524");
		fms.add("12525");

		fms.add("以静制动");
		fms.add("积羽沉舟");
		fms.add("扑朔迷离");
		fms.add("云飞烟灭");
		fms.add("心无旁骛");
		fms.add("披荆斩棘");
		fms.add("困兽之斗");
		fms.add("妙法莲华");
		fms.add("暴虎冯河");
		fms.add("一气呵成");
		fms.add("韬光养晦");
		fms.add("摧经断骨");
		fms.add("血蛊佑身");
		fms.add("明镜止水");
		fms.add("人鬼殊途");
		fms.add("虎踞龙蟠");
		fms.add("浩气凌云");
		fms.add("积健为雄");
		fms.add("清心静气");
		fms.add("利刃加身");
		fms.add("神不守舍");
		fms.add("神力加身");
		fms.add("幻影迷踪");
		fms.add("力挽狂澜");
		fms.add("兽魂俯首");
		fms.add("刚柔兼备");
		fms.add("势如破竹");
		fms.add("凝神一击");
		fms.add("无坚不摧");
		fms.add("气吞山河");
		fms.add("法魂护体");
		fms.add("气聚神凝");
		fms.add("失魂落魄");
		fms.add("鱼龙潜跃");
		fms.add("行气如虹");
		fms.add("神龙摆尾");
	}

	private int id;
	//阵营                  0  1
	private int Camp;
	//位置
	private int man;
	//类型  0属于玩家  1属于召唤兽  2属于野怪3属于灵宝 4属于宝宝 
	private int type;
	//技能和召唤兽和灵宝状态
	private String State_1;
	//名称
	private String manname;
	//总血量
	private int hp_Total;
	//当前血量 
	private int hp_Current;
	//总蓝量
	private int mp_Total;
	//当前蓝量
	private int mp_Current;
	//变身
	private boolean B;
	//怨气值
	private int yqz;
	//怒气值
	private int nqz;
	//是否隐身状态 不为1.0f为隐身
	private float alpha = 1.0f;
	//转生字段
	private int zs;
	//喊话
	private String msg;
	//人物造型
	private String model="img/角色/鬼族/祭剑魂";
	private Integer W;//勋章ID
//	private boolean B=false;

	private List<String> States=new ArrayList<>();//常规状态

	private List<String> aaa;//内丹光环

	/**内丹归类*/
	public void initState(){
		if (States==null) {return;}
		for (int i = States.size()-1; i>=0; i--) {
			String type=States.get(i);
			if (type.startsWith("tj")||type.startsWith("mj")||type.startsWith("xl")||type.startsWith("rj")){
				if (aaa==null) {aaa=new ArrayList<>();}
				aaa.add(type);
				States.remove(i);
			}
		}
	}
	/**判断是否属于状态列表中*/
	public boolean isstate(String type){
		if ("金".equals(type)|| "木".equals(type)|| "水".equals(type)|| "土".equals(type)|| "火".equals(type)|| "1876".equals(type)|| "1887".equals(type)) {
			deletestate("清除五行");
			return true;
		}else if ("遗忘".equals(type)|| "封印".equals(type)|| "昏睡".equals(type)|| "混乱".equals(type)) {
			if ("封印".equals(type)) {
				deletestate("中毒");
			}
			deletestate("封印");
			deletestate("昏睡");
			deletestate("混乱");
			deletestate("遗忘");
			return true;
		}else if ("骨盾".equals(type)|| "减人仙".equals(type)|| "减魔鬼".equals(type)|| "庇护".equals(type)||
				"中毒".equals(type)|| "力量".equals(type)|| "抗性".equals(type)||
				"加速".equals(type)|| "归墟".equals(type)|| "毒针轻刺".equals(type)|| "回魂咒".equals(type)|| "分身".equals(type)||
				"化羽".equals(type)|| "阴阳逆转".equals(type)|| "smmh".equals(type)|| "减速".equals(type)|| "天蓬转世".equals(type) || "乾坤遮天".equals(type)|| "赤芒".equals(type)|| "青峰".equals(type)|| "金石".equals(type)) { //幻方
			return true;
		}else if ("风水".equals(type)|| "雷火".equals(type)|| "鬼力".equals(type)|| "玉净散".equals(type)) {
			deletestate("风水");
			deletestate("雷火");
			deletestate("鬼力");
			deletestate("玉净散");
			return true;
		}else if ("6029".equals(type)) {
			String[] values={"6029","遗忘","封印","中毒","昏睡","混乱","fbJge","fbQw"};
			RemoveAbnormal(values);
			return true;
		}else if ("7009".equals(type)) {
			deletestate("昏睡");
			deletestate("混乱");
			deletestate("遗忘");
			deletestate("7009");
			return true;
		}else if ("1237".equals(type)|| "1237A".equals(type)|| "1237B".equals(type)) {
			String[] values={"1237","1237A","1237B"};
			RemoveAbnormal(values);
			return true;
		}else if ("1238".equals(type)){
			deletestate("1238");
			return true;
		}else if ("步步相逼".equals(type) || "焕然新生".equals(type) || "紫燕翻飞".equals(type) || "一矢中的".equals(type) || "一飞冲天".equals(type) || "展翅欲飞".equals(type) || "化险为夷".equals(type) || "风荷送香".equals(type) || "战意".equals(type) || "破甲".equals(type)){
			deletestate(type);
			return true;
		}else {//判断是否为法宝状态
			for (int i = 0; i < fbs.length; i++) {
				if (fbs[i].equals(type)) {
					deletestate(type);
					return true;
				}
			}
		}

		//判断法门
		for (String fm : fms) {
			if (fm.equals(type)) {
				deletestate(type);
				return true;
			}
		}
		return false;
	}
	/**状态添加 */
	public void addstate(String typess){
		if (typess==null) {
            return;
        }
		String[] types=typess.split("\\|");
		for (int i = 0; i < types.length; i++) {
			String type=types[i];
			if("隐身".equals(type)){
				alpha=0.3f;
			}else if (!States.contains(type)&&isstate(type)) {
				for (int k=States.size()-1;k>=0;k--){
					if ("金石".equals(States.get(k))|| "赤芒".equals(States.get(k))|| "青峰".equals(States.get(k)))//幻方
                    {
                        States.remove(k);
                    }
				}
				States.add(type);
			}else if(type.equals("550065") || type.equals("550066")){
				States.add(type);
			}
		}
	}
	/**状态删除*/
	public void deletestate(String typess){
		if (typess==null) {
            return;
        }
		String[] types=typess.split("\\|");
		for (int i = 0; i < types.length; i++) {
			String type=types[i];
			if ("清除状态".equals(type)) {
				String[] values={"减人仙","减魔鬼","庇护","遗忘","封印","中毒","昏睡","混乱","金","木","水","火","土","1876","力量","抗性","加速","smmh","减速","1887"};
				RemoveAbnormal(values);
			}else if ("清除异常状态".equals(type)) {
				String[] values={"遗忘","封印","中毒","昏睡","混乱","fbJge","fbQw","1232","1869","bbss"};
				RemoveAbnormal(values);
			}else if ("清除五行".equals(type)) {
				String[] values={"金","木","水","火","土","1876","1887"};
				RemoveAbnormal(values);
			}else if ("非控制减益".equals(type)) {
				String[] values={"减速","减人仙","减魔鬼","中毒"};
				RemoveAbnormal(values);
			}else if ("隐身".equals(type)) {
				alpha=1.0f;
			}else if ("1238".equals(type)) {
				String[] values={"1238"};
				RemoveAbnormal(values);
			}else {
				States.remove(type);
			}
		}
	}
	/**
	 * 清除指定状态
	 */
	public void RemoveAbnormal(String[] values){
		for (int j = 0; j < values.length; j++) {
			States.remove(values[j]);
		}
	}
	/**绘制状态*/
	public void draw1(Graphics g, long time, int x, int y) {
		lingxidraw = true;
		for (int i = 0; i < States.size(); i++) {
			String type = States.get(i);
			if (drawDown.contains(type)) {
                continue;
            }
			if (lingxistate.contains(type)) {
				if (!lingxidraw) {
					continue;
				}
				lingxidraw = false;
				type = lingxistate.get(0);
			}
			int x1=0,y1=0;
			if ("分身".equals(type)){
				x1=-20;y1=-20;
			}
			Sprite State = SpriteFactory.Prepare(GetTcpPath.getBuffTcp(type));
			if (State != null) {
				State.updateToTime(time,0);
				if("分身".equals(type)){
					State.draw(g, x+x1-70, y+y1);
				}else{
					State.draw(g, x+x1, y+y1);

				}
			}
		}
	}
	/**绘制状态*/
	public void draw2(Graphics g,long time,int x,int y){
		for (int i = 0; i < States.size(); i++) {
			String type=States.get(i);
			if (drawDown.contains(type)) {
				Sprite State=SpriteFactory.Prepare(GetTcpPath.getBuffTcp(type));
				if (State!=null) {
					State.updateToTime(time,0);
					State.draw(g, x, y);
				}
			}
		}
		if (aaa!=null&&aaa.size()!=0) {
			try {
				Sprite State=SpriteFactory.Prepare(GetTcpPath.getBuffTcp(aaa.get(FightingMixDeal.CurrentRound%aaa.size())));
				if (State!=null) {
					State.updateToTime(time,0);
					State.draw(g, x, y);
				}
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}
		}
	}
	/**
	 * 血蓝变化
	 * @return
	 */
	public void chang(int hp,int mp,int yq,int nq){
		int myman=FightingMixDeal.myman();
		if (hp!=0) {
			hp_Current=Article.xiugai(hp_Total, hp_Current, hp);
			if (FightingMixDeal.camp==Camp&&(myman==man||myman+5==man)) {
				Article.fightingarticlehp(this,hp_Current);
			}
		}
		if (mp!=0) {
			mp_Current=Article.xiugai(mp_Total, mp_Current, mp);
			if (FightingMixDeal.camp==Camp&&(myman==man||myman+5==man)) {
				Article.fightingarticlemp(this,mp_Current);
			}
		}
		if (yq!=0) {
			this.yqz+=yq;
			if (FightingMixDeal.camp==Camp&&myman==man) {
				FightingMixDeal.yqz=this.yqz+"";
			}
		}
		if (nq!=0) {
			this.nqz+=nq;
			if (FightingMixDeal.camp==Camp&&myman==man) {
				FightingMixDeal.nqz=this.nqz+"";
			}
		}

	}
	/**
	 * 状态查找
	 * @return
	 */
	public boolean ztcz(String type){
		for (int i = 0; i < States.size(); i++) {
			if (States.get(i).equals(type)) {
                return true;
            }
		}
		return false;
	}
	/**
	 * 查找制定的信息
	 * @return
	 */
	public List<TypeState> cxxx(String type){
		List<TypeState> xx=new ArrayList<>();
		String[] v=State_1.split("\\|");
		for (int i = 0; i < v.length; i++) {
			String[] v2=v[i].split("=");
			if (!v2[0].equals(type)) {
                continue;
            }
			String[] v3=v2[1].split("\\_");
			for (int j = 0; j < v3.length; j++) {
				String[] v4=v3[j].split("\\-");
				TypeState state=new TypeState();
				state.setType(v4[0]);
				state.setState(Integer.parseInt(v4[1]));
				xx.add(state);
			}
		}
		return xx;
	}
	public int getType() {
		return type;
	}
	public void setType(int type) {
		this.type = type;
	}

	public String getState_1() {
		return State_1;
	}
	public void setState_1(String state_1) {
		State_1 = state_1;
	}
	public String getManname() {
		return manname;
	}
	public void setManname(String manname) {
		this.manname = manname;
	}
	public int getCamp() {
		return Camp;
	}
	public void setCamp(int camp) {
		Camp = camp;
	}
	public int getMan() {
		return man;
	}
	public void setMan(int man) {
		this.man = man;
	}

	public int getHp_Total() {
		return hp_Total;
	}
	public void setHp_Total(int hp_Total) {
		this.hp_Total = hp_Total;
	}
	public int getHp_Current() {
		return hp_Current;
	}
	public void setHp_Current(int hp_Current) {
		this.hp_Current = hp_Current;
	}
	public int getMp_Total() {
		return mp_Total;
	}
	public void setMp_Total(int mp_Total) {
		this.mp_Total = mp_Total;
	}
	public int getMp_Current() {
		return mp_Current;
	}
	public void setMp_Current(int mp_Current) {
		this.mp_Current = mp_Current;
	}
	public List<String> getStates() {
		return States;
	}

	//变身
	public void setB(boolean B){this.B=B;};
	public boolean getB(){return  B;};

	//	public boolean getB(){return B; }
//	public void setB(boolean B){this.B=B;}
	public void setStates(List<String> states) {
		States = states;
	}
	public float getAlpha() {
		return alpha;
	}
	public void setAlpha(float alpha) {
		this.alpha = alpha;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public int getZs() {
		return zs;
	}
	public void setZs(int zs) {
		this.zs = zs;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public int getYqz() {
		return yqz;
	}
	public void setYqz(int yqz) {
		this.yqz = yqz;
	}
	public int getNqz() {
		return nqz;
	}
	public void setNqz(int nqz) {
		this.nqz = nqz;
	}
	public Integer getW() {
		return W;
	}
	public void setW(Integer w) {
		W = w;
	}
	public String getModel() {
		return model;
	}
	public void setModel(String model) {
		this.model = model;
	}
	//路径$额外条件_等级_动作_颜色& 
	public NewPart getPart(){//路径_等级_动作_颜色
		String[] v=model.split("\\&");
		NewPart parts=null;
		for (int i = 0; i < v.length; i++) {
			if (v[i].startsWith("W")) {
				W=Integer.parseInt(v[i].substring(1));
				continue;
			}
			String[] vs=v[i].split("\\_");
			String skin=vs[0];
			int lvl=0,act=-2;
			String color=null;
			if (vs.length==1) {
				lvl=1;
				act=7;
			}else {
				if (vs.length>1) {lvl=Integer.parseInt(vs[1]);}
				if (vs.length>2) {act=Integer.parseInt(vs[2]);}
				if (vs.length>3) {color=vs[3];}
			}
			NewPart part=SpriteFactory.createPart(skin, act, lvl, color);
			if (parts==null) {parts=part;}
			else {parts=parts.addPart(part);}
		}
		return parts;
	}
}
